<?php
/**
 * Smarty plugin
 * @category VaselinEngine
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {radio} function plugin
 *
 * Type:     function<br>
 * Name:     radio<br>
 * Purpose:  print out a radio input. Used by Bel_Forms_Builder
 * @author Konstantin Shamko <konstantin.shamko@gmail.com>
 * @param array parameters
 * @param Smarty
 * @return string|null
 */
function smarty_function_radio($params,&$smarty){

	if (!isset($params['name'])){
		$smarty->trigger_error("<b>FormGenerator (input_plugin) warning:<b/> missing 'name' parameter");
		$error_flag=1;
	}
	
	if($error_flag) return;

	foreach($params['options'][0] as $value=>$option){		
		if($params['value']==$value){
			$selected = 'checked="checked"';
		}else{
			$selected = null;
		}
		
		echo $option.'<input type="radio" name="'.$params['name'].'" value="'.$value.'" '.$selected.'/><br/>';
	}
}	